package com.kikoulol.jarmoryextactor;

import java.util.ArrayList;
import java.util.List;

import noNamespace.ArenaTeam;
import noNamespace.CharacterTab;
import noNamespace.Item;
import noNamespace.PageDocument;

import org.apache.xmlbeans.XmlException;

import com.kikoulol.jarmoryextactor.utils.Utils;

public class Character {
	// XML FILES
	private noNamespace.Character character;
	private CharacterTab characterTab;
	
	private Stats stats;
	private List<Team> arenaTeams;
	private List<com.kikoulol.jarmoryextactor.Item> items;
	
	private String armoryUrl;
	private String charUrl;
	private String name;
	private String titleId;
	private String teamRank;
	private String suffix;
	private String seasonGamesWon;
	private String seasonGamesPlayed;
	private String realm;
	private String raceId;
	private String race;
	private String prefix;
	private String points;
	private String level;
	private String lastModified;
	private String guildUrl;
	private String guildName;
	private String guildId;
	private String guild;
	private String genderId;
	private String gender;
	private String gamesWon;
	private String gamesPlayed;
	private String factionId;
	private String faction;
	private String contribution;
	private String classUrl;
	private String classId;
	private String classType;
	private String battleGroup;
	
	public Character(String armoryUrl, String charUrl) throws XmlException, InterruptedException {
		this.armoryUrl = armoryUrl;
		this.charUrl = charUrl;
		
		String url = armoryUrl + "character-sheet.xml?" + charUrl;
		String xml = Utils.getArmoryXml(url);
			
		PageDocument charDoc = PageDocument.Factory.parse(xml);
		character = charDoc.getPage().getCharacterInfo().getCharacter();
		characterTab = charDoc.getPage().getCharacterInfo().getCharacterTab();
		arenaTeams = new ArrayList<Team>();
		items = new ArrayList<com.kikoulol.jarmoryextactor.Item>();
		init(character);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	private void init(noNamespace.Character character) throws XmlException {
		
		setName(character.getName());
		setBattleGroup(character.getBattleGroup());
		setCharUrl(character.getCharUrl());
		setClassId(character.getClassId());
		setClassType(character.getClass1());
		setClassUrl(character.getClassUrl());
		setContribution(character.getContribution());
		setFaction(character.getFaction());
		setFactionId(character.getFactionId());
		setGamesPlayed(character.getGamesPlayed());
		setGamesWon(character.getGamesWon());
		setGender(character.getGender());
		setGenderId(character.getGenderId());
		setGuild(character.getGuild());
		setGuildId(character.getGuildId());
		setGuildName(character.getGuildName());
		setGuildUrl(character.getGuildUrl());
		setLastModified(character.getLastModified());
		setLevel(character.getLevel());
		setPoints("" + character.getPoints());
		setPrefix(character.getPrefix());
		setRace(character.getRace());
		setRaceId(character.getRaceId());
		setRealm(character.getRealm());
		setSeasonGamesPlayed(character.getSeasonGamesPlayed());
		setSeasonGamesWon(character.getSeasonGamesWon());
		setSuffix(character.getSuffix());
		setTeamRank(character.getTeamRank());
		stats = new Stats(characterTab);
		
	}

	public String getCharUrl() {
		return charUrl;
	}

	public void setCharUrl(String charUrl) {
		this.charUrl = charUrl;
	}

	public List<Team> getArenaTeams() throws XmlException, InterruptedException {
		arenaTeams = new ArrayList<Team>();
		for(ArenaTeam team : character.getArenaTeams().getArenaTeamArray()) {
			Team myTeam = new Team(armoryUrl,team.getUrl());
			arenaTeams.add(myTeam);
		}
		return arenaTeams;
	}

	public void setArenaTeams(List<Team> arenaTeams) {
		this.arenaTeams = arenaTeams;
	}


	public String getTitleId() {
		return titleId;
	}

	public void setTitleId(String titleId) {
		this.titleId = titleId;
	}

	public String getTeamRank() {
		return teamRank;
	}

	public void setTeamRank(String teamRank) {
		this.teamRank = teamRank;
	}

	public String getSuffix() {
		return suffix;
	}

	public void setSuffix(String suffix) {
		this.suffix = suffix;
	}

	public String getSeasonGamesWon() {
		return seasonGamesWon;
	}

	public void setSeasonGamesWon(String seasonGamesWon) {
		this.seasonGamesWon = seasonGamesWon;
	}

	public String getSeasonGamesPlayed() {
		return seasonGamesPlayed;
	}

	public void setSeasonGamesPlayed(String seasonGamesPlayed) {
		this.seasonGamesPlayed = seasonGamesPlayed;
	}

	public String getRealm() {
		return realm;
	}

	public void setRealm(String realm) {
		this.realm = realm;
	}

	public String getRaceId() {
		return raceId;
	}

	public void setRaceId(String raceId) {
		this.raceId = raceId;
	}

	public String getRace() {
		return race;
	}

	public void setRace(String race) {
		this.race = race;
	}

	public String getPrefix() {
		return prefix;
	}

	public void setPrefix(String prefix) {
		this.prefix = prefix;
	}

	public String getPoints() {
		return points;
	}

	public void setPoints(String points) {
		this.points = points;
	}

	public String getLevel() {
		return level;
	}

	public void setLevel(String level) {
		this.level = level;
	}

	public String getLastModified() {
		return lastModified;
	}

	public void setLastModified(String lastModified) {
		this.lastModified = lastModified;
	}

	public String getGuildUrl() {
		return guildUrl;
	}

	public void setGuildUrl(String guildUrl) {
		this.guildUrl = guildUrl;
	}

	public String getGuildName() {
		return guildName;
	}

	public void setGuildName(String guildName) {
		this.guildName = guildName;
	}

	public String getGuildId() {
		return guildId;
	}

	public void setGuildId(String guildId) {
		this.guildId = guildId;
	}

	public String getGuild() {
		return guild;
	}

	public void setGuild(String guild) {
		this.guild = guild;
	}

	public String getGenderId() {
		return genderId;
	}

	public void setGenderId(String genderId) {
		this.genderId = genderId;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public String getGamesWon() {
		return gamesWon;
	}

	public void setGamesWon(String gamesWon) {
		this.gamesWon = gamesWon;
	}

	public String getGamesPlayed() {
		return gamesPlayed;
	}

	public void setGamesPlayed(String gamesPlayed) {
		this.gamesPlayed = gamesPlayed;
	}

	public String getFactionId() {
		return factionId;
	}

	public void setFactionId(String factionId) {
		this.factionId = factionId;
	}

	public String getFaction() {
		return faction;
	}

	public void setFaction(String faction) {
		this.faction = faction;
	}

	public String getContribution() {
		return contribution;
	}

	public void setContribution(String contribution) {
		this.contribution = contribution;
	}

	public String getClassUrl() {
		return classUrl;
	}

	public void setClassUrl(String classUrl) {
		this.classUrl = classUrl;
	}

	public String getClassId() {
		return classId;
	}

	public void setClassId(String classId) {
		this.classId = classId;
	}

	public String getClassType() {
		return classType;
	}

	public void setClassType(String classType) {
		this.classType = classType;
	}

	public String getBattleGroup() {
		return battleGroup;
	}

	public void setBattleGroup(String battleGroup) {
		this.battleGroup = battleGroup;
	}

	public Stats getStats() {
		return stats;
	}

	public List<com.kikoulol.jarmoryextactor.Item> getItems() throws XmlException {
		
		// items init
		for (Item item : characterTab.getItems().getItemArray()) {
			com.kikoulol.jarmoryextactor.Item it = new com.kikoulol.jarmoryextactor.Item(armoryUrl,item);
			items.add(it);
		}
		
		return items;
	}

	

}
